/*
 * @Author: fishroom
 * @Date: 2022-09-29 14:15:58
 * @LastEditTime: 2022-09-29 15:41:49
 * @FilePath: \koa-blog-backend\app\util\swagger.js
 */
const path = require("path");
const router = require("koa-router")(); //引入路由函数
const swaggerJSDoc = require("swagger-jsdoc");
const swaggerDefinition = {
  info: {
    title: "个人网站api借口",
    version: "1.0.0",
    description: "API",
  },
  host: "localhost:3003",
  basePath: "/", // Base path (optional)
};
const options = {
  swaggerDefinition,
  apis: [path.join(__dirname, "../router/*.js")], // 写有注解的router的存放地址, 最好path.join()
};
const swaggerSpec = swaggerJSDoc(options);
// 通过路由获取生成的注解文件
router.get("/swagger.json", async function (ctx) {
  ctx.set("Content-Type", "application/json");
  ctx.body = swaggerSpec;
});
module.exports = router;
